package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseCategoryTrademark;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.model.product.CategoryTrademarkVo;
import com.atguigu.gmall.product.service.BaseCategoryTrademarkService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/baseCategoryTrademark")
@Api(tags="分类品牌管理")
public class BaseCategoryTrademarkController {

    @Autowired
    private BaseCategoryTrademarkService baseCategoryTrademarkService;
    /**
     * /admin/product/baseCategoryTrademark/findTrademarkList/{category3Id}
     * 根据category3Id获取品牌列表
     * Get
     */
    @GetMapping("/findTrademarkList/{category3Id}")
    @ApiOperation("根据category3Id获取品牌列表")
    public Result findTrademarkList(@PathVariable Long category3Id){
        List<BaseTrademark>TrademarkList=baseCategoryTrademarkService.findTrademarkList(category3Id);
        return Result.ok(TrademarkList);
    }

    /**
     * /admin/product/baseCategoryTrademark/findCurrentTrademarkList/{category3Id}
     * 根据category3Id获取可选品牌列表
     * Get
     */
    @GetMapping("/findCurrentTrademarkList/{category3Id}")
    @ApiOperation("根据category3Id获取可选品牌列表")
    public Result findCurrentTrademarkList(@PathVariable Long category3Id){
        List<BaseTrademark>TrademarkList=baseCategoryTrademarkService.findCurrentTrademarkList(category3Id);
        return Result.ok(TrademarkList);
    }

    /**
     * /admin/product/baseCategoryTrademark/save
     * 保存分类品牌关联
     * Post
     */
    @PostMapping("/save")
    @ApiOperation("保存分类品牌关联")
    public Result save(
            @RequestBody CategoryTrademarkVo categoryTrademarkVo
            ){
        baseCategoryTrademarkService.save(categoryTrademarkVo);
        return Result.ok();
    }

    /**
     * /admin/product/baseCategoryTrademark/remove/{category3Id}/{trademarkId}
     * 删除分类品牌关联
     * Delete
     */
    @DeleteMapping("/remove/{category3Id}/{trademarkId}")
    @ApiOperation("删除分类品牌关联")
    public Result remove(
            @PathVariable Long category3Id,
            @PathVariable Long trademarkId
    ){
        QueryWrapper<BaseCategoryTrademark> baseCategoryTrademarkQueryWrapper = new QueryWrapper<>();
        baseCategoryTrademarkQueryWrapper.eq("category3_id",category3Id);
        baseCategoryTrademarkQueryWrapper.eq("trademark_id",trademarkId);
        baseCategoryTrademarkService.remove(baseCategoryTrademarkQueryWrapper);
        return Result.ok();
    }
}
